package guoanmaker.operator.business.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import guoanmaker.operator.business.model.BackgroundPicture;
import guoanmaker.operator.business.model.InRoundPhone;
import guoanmaker.operator.business.model.OperatorManage;
import guoanmaker.operator.business.service.OperatorBackgroundPictureServiceInterface;
import guoanmaker.operator.business.service.OperatorManageServiceInterface;
import guoanmaker.operator.helper.common.AjaxJson;
import guoanmaker.operator.helper.common.abstractobj.ApiController;
import io.swagger.annotations.ApiOperation;
/**
 * 保存登录页面管理员信息
* @ClassName: OperatorManageController
* @Description:TODO (这里用一句话描述这个类的作用) 
* @author lihongyu
* @date 2017年9月4日 下午9:10:25 
*  
 */
@RestController
@RequestMapping(ApiController.OPERATOR_MANAGE)
public class OperatorManageController {
	@Autowired
	 private  AjaxJson ajaxJson;
	@Autowired
	private OperatorManageServiceInterface operatorManageServiceInterface;
	  @ApiOperation(value = "保存登录管理员信息", notes = "保存登录管理员信息包括新增与修改 ")
	    @PostMapping(value = "saveOperatorManage")
	    public AjaxJson saveOperatorManage(@RequestBody InRoundPhone inRoundPhone) {
	    	
	    	try{
	    		OperatorManage ow=inRoundPhone.getOperatorManage();
	    		ow.setCreateDate(new Date());
	    		OperatorManage    operatorManage = operatorManageServiceInterface.saveOperatorManage(ow);
	        ajaxJson.setSuccess(true).setStatus(200).setData(operatorManage);
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		 ajaxJson.setSuccess(true).setStatus(250).setData(null);
	    	}
	        return ajaxJson;
	    }
	  
	  @ApiOperation(value = "查询所有管理员登录信息", notes = "查询所有管理员登录信息")
	    @PostMapping(value = "getAllOperatorManage")
	    public AjaxJson getAllOperatorManage() {
	    	try{
	    	List<OperatorManage> ops=operatorManageServiceInterface.getAllOperatorManage();
	    	if(ops.size()>0){
	        ajaxJson.setSuccess(true).setStatus(200).setData(ops.get(0));
	        }else{
	        	ajaxJson.setSuccess(true).setStatus(200).setData(null);
	        }
	    	}catch(Exception e){
	    		e.printStackTrace();
	    		 ajaxJson.setSuccess(false).setStatus(250).setData(null);
	    	}
	    	return ajaxJson;
	    }
}
